import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.geom.AffineTransform;


public class Link {
	
	public final static int ARR_SIZE = 8;
	Point from;
	Point to;
	
	public void drawLink(Graphics g1){
		this.drawLinkWithArrow(g1, from.x, from.y, to.x, to.y);
	}
	
	private void drawLinkWithArrow(Graphics g1, int x1, int y1, int x2, int y2) {
        Graphics2D g = (Graphics2D) g1.create();

        double dx = x2 - x1, dy = y2 - y1;
        double angle = Math.atan2(dy, dx);
        int len = (int) Math.sqrt(dx*dx + dy*dy);
        AffineTransform at = AffineTransform.getTranslateInstance(x1, y1);
        at.concatenate(AffineTransform.getRotateInstance(angle));
        g.transform(at);

        // Draw horizontal arrow starting in (0, 0)
        g.drawLine(0, 0, len, 0);
        g.fillPolygon(new int[] {len, len - Link.ARR_SIZE, len - Link.ARR_SIZE, len},
                      new int[] {0, - Link.ARR_SIZE, Link.ARR_SIZE, 0}, 4);
    }
	
	public Link() {
		super();
	}
	
	public Link(Point from, Point to) {
		super();
		this.from = from;
		this.to = to;
	}
	public Point getFrom() {
		return from;
	}
	public void setFrom(Point from) {
		this.from = from;
	}
	public Point getTo() {
		return to;
	}
	public void setTo(Point to) {
		this.to = to;
	}
	
	@Override
	public String toString() {
		return "Link [from=" + from + ", to=" + to + "]";
	}
	
}
